﻿using FluentValidation;
using SDF.Core.Data;
using SDF.Data;
using SDF.Plugin.Misc.DynamicEntity.Domain;
using SDF.Plugin.Misc.DynamicEntity.Models;
using SDF.Services.Localization;
using SDF.Web.Framework.Validators;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace SDF.Plugin.Misc.DynamicEntity.Validators.DynamicEntity
{
    public class GenerateEntityValidator : BaseSDFValidator<GenerateEntityModel>
    {
        public GenerateEntityValidator(ILocalizationService localizationService, IDbContext dbContext, IRepository<DynamicEntityItem> entityRepository)
        {
            RuleFor(x => x.SAPInstance)
                .NotEmpty()
                .WithMessage(localizationService.GetResource("Plugins.Misc.DynamicEntity.SAPInstance.Required"));

            RuleFor(x => x.SAPFunctionName)
                .NotEmpty()
                .WithMessage(localizationService.GetResource("Plugins.Misc.DynamicEntity.SAPFunctionName.Required"));

            RuleFor(x => x.SAPFunctionName).Length(3, 30);

            RuleFor(x => x.SAPInstance)
                .Must((model, x) =>
                {
                    return x != "0";
                }).WithMessage(localizationService.GetResource("Plugins.Misc.DynamicEntity.SAPInstance.Required"));
        }
    }
}